home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / gold / pick.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.8 KB  |  109 lines

  1. /*
  2.  * The original copyright owners of the accompanying source code files have
  3.  * agreed to place such code into the public domain.  Accordingly, anyone
  4.  * who receives or obtains a copy of such source code is freely entitled to
  5.  * reproduce, use and otherwise exploit such code (including the right to
  6.  * make derivative works), at his/her own risk and expense, without any
  7.  * obligation or liability to the original copyright owners.
  8.  *
  9.  * We would appreciate (but do not require) that the following message be
  10.  * included in any derivative works:
  11.  *
  12.  * "Portions of this program were developed by Peter Broadwell, Rob Myers
  13.  * and Robin Schaufler while working in Silicon Valley."
  14.  *
  15.  * The accompanying source code files and related documentation materials
  16.  * are distributed on an "AS IS" basis, without any warranties or
  17.  * guarantees of any kind.  All implied warranties, including the implied
  18.  * warranties of merchantability and of fitness for any particular purpose,
  19.  * are expressly disclaimed.
  20.  */
  21. #include <stdio.h>
  22. #include "gl.h"
  23. #include "pick.h"
  24.  
  25.  
  26.     /*
  27.      * routines to use 32 bit integers in the 16 bit name mechanism
  28.      */
  29. pushLongName(longName)
  30.     long longName;
  31. {
  32.     pushname(longName & 0xffff);    /* high bits of name */
  33.     pushname(longName >> 16);        /*  low bits of name */
  34. }
  35.  
  36. popLongName()
  37. {
  38.     popname();
  39.     popname();
  40. }
  41.  
  42.     Object
  43. getLongName(base)
  44.     short *base;
  45. {
  46.     return (Object)((*base & 0xffff) | (*(base+1) << 16));
  47. }
  48.  
  49.     /*
  50.      *  hit processing utilities
  51.      */
  52. gethit(hit, base, found)
  53.     register hitstruct *hit;
  54.     register short base[];
  55.     register short found;
  56. {
  57.     register short i, names, obase;
  58.  
  59.     /* dumplist(base, found); /* */
  60.  
  61.     if (found <= 0) {
  62.     if (found <0)
  63.         fprintf(stderr, "gethit: hey, hits overflowed the hitlist!\n");
  64.     return 0;
  65.     }
  66.  
  67.     i = 0;
  68.     while (found-- > 1) {
  69.     names = base[i++];
  70.     while (names--)
  71.         obase = base[i++]; /* obase is only used to debug */
  72.     }
  73.     /* last found hit entry */
  74.     if ((names = base[i++]) >= 0) {
  75.     names -= 4; i += 4;    /* step over initial NULL and "us" entries */
  76.     for (hit->depth=0; names>0; names-=2, i+=2)
  77.         hit->hitlist[hit->depth++] = getLongName(&base[i]);
  78.     /* fprintf(stderr, "gethit: returns %d\n", hit->depth); /* */
  79.     return hit->depth;
  80.     }
  81.     else fprintf(stderr,"gethit: trouble in the hitlist! names = %d\n", names);
  82.  
  83.     return 0;
  84. }
  85.  
  86. dumplist(base, found)
  87.     register short base[];
  88.     register short found;
  89. {
  90.     register short i, names;
  91.  
  92.     fprintf(stderr,"dumplist: found %d %s\n", found, (found>1)?"hits":"hit");
  93.     if (found < 0)
  94.     found = HITENTRIES;
  95.     i = 0;
  96.     while (found--) {
  97.     if ((names = base[i++]) <= 0) {
  98.         continue;
  99.     }
  100.     else {
  101.         fprintf(stderr,"\t%d names", names);
  102.         while (names-- && (i<HITENTRIES))
  103.         fprintf(stderr,",0x%x", base[i++]);
  104.         fprintf(stderr,"\n");
  105.     }
  106.     }
  107.     fflush(stderr);
  108. }
  109.